﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using StripeOne.Core.Cache;
using StripeOne.Core.Models;
using StripeOne.Core;
using StripeOne.Blog.Base.Common;

namespace StripeOne.Blog
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            #region Blog

            routes.MapRoute(
                    "Home_BLO",
                    "Home/{action}",
                    new { controller = "Home", action = "Index", moduleCode = "BLO" }
                );

            #endregion

            #region Admin

            //Home
            routes.MapRoute(
                    "Home_BLA",
                    "Admin/Home/{action}",
                    new { controller = "AdminHome", action = "Index", moduleCode = "BLA" }
                );
            // -/Home

            //Posts
            routes.MapRoute(
                    "PostsIndex_BLA",
                    "Admin/Posts",
                    new { controller = "AdminPosts", action = "Index", moduleCode = "BLA" }
                );

            routes.MapRoute(
                    "PostsAdd_BLA",
                    "Admin/Posts/Add",
                    new { controller = "AdminPosts", action = "Add", moduleCode = "BLA" }
                );

            routes.MapRoute(
                    "PostsEdit_BLA",
                    "Admin/Posts/Edit/{id}",
                    new { controller = "AdminPosts", action = "Edit", moduleCode = "BLA" }
                );

            routes.MapRoute(
                    "PostsDelete_BLA",
                    "Admin/Posts/Delete",
                    new { controller = "AdminPosts", action = "Delete", moduleCode = "BLA" }
                );

            // -/Posts

            #endregion

            #region Defaults

            routes.MapRoute(
                    "DefaultHome_BLA", // Route name
                    "Admin", // URL with parameters
                    new { controller = "AdminHome", action = "Index", moduleCode = "BLA" }
                );

            routes.MapRoute(
                    "Default_BLA", // Route name
                    "Admin/{controller}/{action}/{id}", // URL with parameters
                    new { controller = "AdminHome", action = "Index", moduleCode = "BLA" }
                );

            routes.MapRoute(
                    "DefaultHome", // Route name
                    "", // URL with parameters
                    new { controller = "Home", action = "Index", moduleCode = "BLO" }
                );

            routes.MapRoute(
                    "Default", // Route name
                    "{controller}/{action}/{id}", // URL with parameters
                    new { controller = "Home", action = "Index", moduleCode = "BLO" }
                );

            #endregion
        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
    }
}